
package jskiller;

import jskiller.gui.console.JskillerConsole;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;

import org.lwjgl.opengl.Display;
import org.lwjgl.Sys;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.awt.Font;

import jskiller.gui.TrueTypeFont;

public class Main {
  public static final Logger LOGGER = Logger.getLogger(Main.class.getName());
  public static final JskillerConsole CONSOLE = JskillerConsole.getInstance();

  int fps;
  int lastFPS;
  long lastFrame;

  static {
    try {
      LOGGER.addHandler(new FileHandler("errors.log",true));
    }
    catch(IOException ex) {
      LOGGER.log(Level.WARNING,ex.toString(),ex);
    }
  }
  
  

  public static void main(String[] args) {
    Main main = null;
    try {
      System.out.println("Hallo");

      main = new Main();
      main.create();

      main.CONSOLE.create();

      main.run();
    }
    catch(Exception ex) {
      LOGGER.log(Level.SEVERE,ex.toString(),ex);
    }
    finally {
      if(main != null) {
        main.destroy();
      }
    }
  }

  public Main() {

  }

  public void create(){

  }

  public void destroy() {
   
  }


  public void run(){
      //while(!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {

      getDelta();
      lastFPS = (int)Sys.getTime();
      while(!Display.isCloseRequested()) {
         /* if(Display.isVisible()) {
                //update
              CONSOLE.render_all();
          }
          else {
            if(Display.isDirty()) {
              CONSOLE.render_all();
            }
            try {
              Thread.sleep(100);
            }
            catch(InterruptedException ex) {
            }
          }*/
          updateFPS();
          CONSOLE.render_all();

          /*try {
              Thread.sleep(10);
          }
          catch(InterruptedException ex) {
          }*/
          
          Display.update();
          Display.sync(60);

        }
  }

  public int getDelta() {
    long time = Sys.getTime();
    int delta = (int) (time - lastFrame);
    lastFrame = time;

    return delta;
}

  public void updateFPS() {
    if (Sys.getTime() - lastFPS > 1000) {
        Display.setTitle("FPS: " + fps);
	fps = 0;
	lastFPS += 1000;
    }
    fps++;
  }

}
